package io.sunny.platform.backend.starter.compression;

import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author SUNNY
 * @Date 2025/7/18 19:47
 * @PackageName: io.sunny.platform.starter.compression
 * @Description: 容器级(Deflate 实现方式)
 * @Version 1.0
 */
@Configuration
public class CompressionConfig {

    @Bean
    public TomcatServletWebServerFactory tomcatFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
        factory.addConnectorCustomizers(connector -> {
            connector.setProperty("compression", "on");
            connector.setProperty("compressionMinSize", "1024");
            connector.setProperty("compressibleMimeType", "text/html,text/xml,text/plain,application/json");
            connector.setProperty("compression", "deflate");
        });

        return factory;
    }
}
